package com.ubao.weibo;


import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.ubao.R;
import com.ubao.activity.MyApp.GoBack;
import com.ubao.base.RequestBaseActivity;
import com.ubao.ui.titlebar.GTitleBar;

public abstract class WeiboOAuthActivity extends RequestBaseActivity {
	public WebView webview;
	protected GTitleBar gTB;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sina_oauth_webview);
		gTB = (GTitleBar) findViewById(R.id.TitleBar);
		webview = (WebView) this.findViewById(R.id.oauth_webview);
		webview.getSettings().setJavaScriptEnabled(true);
		webview.setFocusable(true);
	
		webview.setWebViewClient(new WebViewClient() {
			@Override
			public void onPageFinished(WebView view, String url) {
				Log.i("onPageFinished", url + "网页加载完毕");
				super.onPageFinished(view, url);
			}

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				Log.e("shouldOverrideUrlLoading", "shouldOverrideUrlLoading:"  + url);
				webview.loadUrl(url);
				return super.shouldOverrideUrlLoading(view, url);
			}

			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				Log.e("onPageStarted", "start:" + url);
				WeiboOAuthActivity.this.pageStarted( view,  url,  favicon);
				super.onPageStarted(view, url, favicon);
			}
			
			@Override
			public void onReceivedError(WebView view, int errorCode,
					String description, String failingUrl) {
				Log.e("onReceivedError", "start:" + failingUrl);
				super.onReceivedError(view, errorCode, description, failingUrl);
				finish();
			}
		});
	}
	
	 public abstract void pageStarted(WebView view, String url, Bitmap favicon);
	 
	 protected String getParam(String name,String content,String end){
		 int  i = content.indexOf(name)+name.length();
		 int j = i+content.substring(i).indexOf(end);
		 return content.substring(i, j);
	 }
}
